class Solution {
    public int lengthOfLongestSubstring(String s) {
        int left = 0,right = 0,maxLength = 0;
        int n = s.length();
        int[] count = new int[128];
        while(right < n) {
            char ch = s.charAt(right);
            while(count[ch] == 1) {
                char ch1 = s.charAt(left++);
                count[ch1]--;
            }
            count[ch]++;
            maxLength = Math.max(maxLength,right - left + 1);
            right++;
        }
        return maxLength;
    }
}